package main

import (
	"flag"
	"fmt"
	"reflect"
)

func visit(list []int, f func(int)) {
	for index, v := range list {
		println("index: ", index)
		f(v)
	}
}

// 定义命令行参数skill，从命令行输入 --skill 可以将 = 后的字符串传入传入 skillParam 指针变量
var skillParam = flag.String("skill", "", "skill to perform")

func main() {
	//使用匿名函数打印切片内容
	visit([]int{1, 2, 3, 4}, func(i int) {
		fmt.Println(i)
	})

	reflectParam := reflect.TypeOf(skillParam)
	println(reflectParam.Kind() == reflect.Pointer)

	//解析命令行参数，解析完成后，skillParam 指针变量将指向命令行传入的值。
	flag.Parse()

	var skill = map[string]func(){
		"fire": func() {
			fmt.Println("chicken fire")
		},
		"run": func() {
			fmt.Println("soldier run")
		},
		"fly": func() {
			fmt.Println("angel fly")
		},
	}

	if f, ok := skill[*skillParam]; ok {
		f()
	} else {
		fmt.Println("skill not found")
	}
}
